home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2000 September / september_2000.iso / intercd / root / ^Linux / WindowMaker / wrlib / testrot.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-02-27  |  1.3 KB  |  69 lines

  1.  
  2.  
  3. #include <X11/Xlib.h>
  4. #include "wraster.h"
  5. #include <stdlib.h>
  6. #include <stdio.h>
  7. #include "tile.xpm"
  8. Display *dpy;
  9. Window win;
  10. RContext *ctx;
  11. RImage *img;
  12. Pixmap pix;
  13.  
  14.  
  15. #define MAX(a,b) (a)>(b) ? (a) : (b)
  16.  
  17. int main(int argc, char **argv)
  18. {
  19.     RContextAttributes attr;
  20.     float a;
  21.  
  22.     dpy = XOpenDisplay("");
  23.     if (!dpy) {
  24.     puts("cant open display");
  25.     exit(1);
  26.     }
  27.  
  28.     attr.flags = RC_RenderMode | RC_ColorsPerChannel;
  29.     attr.render_mode = RDitheredRendering;
  30.     attr.colors_per_channel = 4;
  31.     ctx = RCreateContext(dpy, DefaultScreen(dpy), &attr);
  32.  
  33.     if (argc<2) 
  34.     img = RGetImageFromXPMData(ctx, image_name);
  35.     else
  36.     img = RLoadImage(ctx, argv[1], 0);
  37.  
  38.     if (!img) {
  39.     puts(RMessageForError(RErrorCode));
  40.     exit(1);
  41.     }
  42.     win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 10, 10, 
  43.                   MAX(img->width, img->height),
  44.                   MAX(img->height, img->width), 0, 0, 0);
  45.     XMapRaised(dpy, win);
  46.     XFlush(dpy);
  47.  
  48.     a = 0;
  49.     while (1) {
  50.     RImage *tmp;
  51.     
  52.     a = a + 1.0;
  53.     
  54.     tmp = RRotateImage(img, a);
  55.     if (!RConvertImage(ctx, tmp, &pix)) {
  56.         puts(RMessageForError(RErrorCode));
  57.         exit(1);
  58.     }
  59.     RDestroyImage(tmp);
  60.               
  61.     XSetWindowBackgroundPixmap(dpy, win, pix);
  62.     XFreePixmap(dpy, pix);
  63.     XClearWindow(dpy, win);
  64.     XSync(dpy, 0);
  65.     usleep(50000);
  66.     }
  67.     exit(0);
  68. }
  69.